package org.hcyspartnoc.luoxin.controller.user;

import jakarta.annotation.Resource;
import org.hcyspartnoc.luoxin.common.core.AjaxResult;
import org.hcyspartnoc.luoxin.common.core.annotation.Log;
import org.hcyspartnoc.luoxin.common.core.annotation.PreAuthorize;
import org.hcyspartnoc.luoxin.common.core.enums.BusinessType;
import org.hcyspartnoc.luoxin.common.exception.asset.AssetVCounselorException;
import org.hcyspartnoc.luoxin.common.exception.system.SysUserException;
import org.hcyspartnoc.luoxin.common.exception.user.UserContactException;
import org.hcyspartnoc.luoxin.service.user.IUserContactService;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/contact")
public class UserContactController {
    @Resource
    private IUserContactService chatUserContactService;

    @Log(title = "用户·联系人·发送申请", businessType = BusinessType.INSERT)
    @PreAuthorize(auth = "user:contact:apply", descr = "发送添加联系人申请")
    @PostMapping("/apply/{contact:[UGRVugrv]\\d+}")
    public AjaxResult apply(@PathVariable("contact") @Length(min = 2, max = 11, message = "请输入正确的联系人") String contact) throws UserContactException, SysUserException, AssetVCounselorException {
        chatUserContactService.apply(contact);
        return AjaxResult.successMsg();
    }
}
